<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>a 的索引问题</title>
    <style>
        *{
            margin: 5px auto;
            padding: 0px;
            text-align: center;
            
        }
        table{
            border: 1px solid  rgb(0, 0, 0);
            background-color: rgb(206, 255, 239);
        }
        th{
            font-weight: bolder;
        }
        td{
            border: 1px solid rgb(0, 0, 0);
            width: 100px;
            font-size: 17px;
        }
    </style>
</head>
<body>

    <table id="employeeTable">
        <tr>
            <th>Name</th>
            <th>Email</th>
            <th>Salary</th>
            <th>&nbsp;</th>
        </tr>
        <tr>
            <td>Tom</td>
            <td>tom@tom.com</td>
            <td>5000</td>
            <td><a href="deleteEmp?id=001">Delete</a></td>
        </tr>
        <tr>
            <td>Jerry</td>
            <td>Jerry@sohu.com</td>
            <td>8000</td>
            <td><a href="deleteEmp?id=002">Delete</a></td>
        </tr>
        <tr>
            <td>Bob</td>
            <td>bob@tom.com</td>
            <td>10000</td>
            <td><a href="deleteEmp?id=003">Delete</a></td>
        </tr>
    </table>

    <div id="formDiv">
        <h4>添加新员工</h4>
        <table>
            <tr>
                <td class="word">name: </td>
                <td class="inp">
                    <input type="text" name="empName" id="empName">
                </td>
            </tr>
            <tr>
                <td class="word">email: </td>
                <td class="inp">
                    <input type="text" name="email" id="email">
                </td>
            </tr>
            <tr>
                <td class="word">salary: </td>
                <td class="inp">
                    <input type="text" name="salary" id="salary">
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <button id="addEmpButton">
                        Submit
                    </button>
                </td>
            </tr>
        </table>
    </div>

</body>
</html>
<script>

    // 获取所有的超链接
        var allA = document.getElementsByTagName("a");

    // 为每个超链接都绑定一个单击响应函数
    for(let i=0;i<allA.length;i++){

        /*
            for 循环会在页面加载完毕完成之后立即执行，
                而响应函数会在超链接被点击时才执行
                当响应函数执行时，for循环早已执行完毕
        */
        alert("for循环正在执行"+i);
        allA[i].onclick = function delA(){

            alert("响应函数正在执行"+i);
            return false;
        }
    }
</script>